package com.hnkywl.sts.entity.htgl;

import com.hnkywl.sts.entity.base.Sjzdz;
import com.hnkywl.sts.entity.organ.Gc;
import com.hnkywl.sts.entity.xsgl.Xsd;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.List;

/**
 * 说明：销售合同
 * 包:        com.hnkywl.sts.entity.htgl
 * 类描述:    销售合同
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Entity
@Where(clause = "deleted!='1'")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("xsht")
public class Xsht extends Ht {
    /**
     * 销售类型（直达到货销售合同）   hcxs:库存销售（包括：合同销售和库存零售）  zddh:直达到货
     */
    private String xslx;

    /**
     * 回款期限
     */
    private Integer hkqx;

    /**
     * 计算依据
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "JSYJ_SJZDZ_ID")
    private Sjzdz jsyj;

    /**
     * 工程
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "GC_ID")
    private Gc gc;

    /**
     * 发货责任
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "FHZR_SJZDZ_ID")
    private Sjzdz fhzr;

    /**
     * 销售或费用
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "XSFY_SJZDZ_ID")
    private Sjzdz xsfy;

    /**
     * 销售单
     */
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "xsht", targetEntity = Xsd.class)
    @Where(clause = "deleted!='1'")
    private List<Xsd> xsdList;

    /**
     * 关联直达到货的采购合同
     */
    @ManyToOne(cascade = CascadeType.MERGE, targetEntity = Cght.class)
    @JoinColumn(name = "ZDDHCGHT_ID")
    private Cght zddhcght;


    @Formula("(select NVL(sum(t.SBSL),0) from T_BIZ_HTMX t where t.HT_ID=ID and t.deleted!=1)")
    private Double sbsl;

    @Formula("(select NVL(sum(a.SBSL),0) from T_BIZ_XSD t left join T_BIZ_XSMX a on a.XSD_ID=t.ID where t.XSHT_ID=ID and t.ZT='ytj' and t.DELETED!=1)")
    private Double wlyl;


    public Integer getHkqx() {
        return hkqx;
    }

    public void setHkqx(Integer hkqx) {
        this.hkqx = hkqx;
    }

    public Sjzdz getJsyj() {
        return jsyj;
    }

    public void setJsyj(Sjzdz jsyj) {
        this.jsyj = jsyj;
    }

    public Gc getGc() {
        return gc;
    }

    public void setGc(Gc gc) {
        this.gc = gc;
    }

    public Sjzdz getFhzr() {
        return fhzr;
    }

    public void setFhzr(Sjzdz fhzr) {
        this.fhzr = fhzr;
    }

    public Sjzdz getXsfy() {
        return xsfy;
    }

    public void setXsfy(Sjzdz xsfy) {
        this.xsfy = xsfy;
    }

    public String getXslx() {
        return xslx;
    }

    public void setXslx(String xslx) {
        this.xslx = xslx;
    }

    public List<Xsd> getXsdList() {
        return xsdList;
    }

    public void setXsdList(List<Xsd> xsdList) {
        this.xsdList = xsdList;
    }

    public Cght getZddhcght() {
        return zddhcght;
    }

    public void setZddhcght(Cght zddhcght) {
        this.zddhcght = zddhcght;
    }

    public Double getWlyl() {
        return wlyl;
    }

    public void setWlyl(Double wlyl) {
        this.wlyl = wlyl;
    }

    public Double getSbsl() {
        return sbsl;
    }

    public void setSbsl(Double sbsl) {
        this.sbsl = sbsl;
    }
}
